package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class LifeCycleBean implements BeanNameAware, BeanFactoryAware,
        ApplicationContextAware, InitializingBean, DisposableBean {

    public LifeCycleBean() {
        System.out.println("1、Bean的实例化");
    }

    String life;

    public void setLife(String life) {
        System.out.println("2、设置属性");
        this.life = life;
    }

    String beanName;
    BeanFactory beanFactory;
    ApplicationContext applicationContext;
    @Override
    public void setBeanName(String beanName) {
        System.out.println("3、setBeanName(String beanName)");
        this.beanName = beanName;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("4、setBeanFactory(BeanFactory beanFactory)");
        this.beanFactory = beanFactory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("5、setApplicationContext(ApplicationContext applicationContext)");
        this.applicationContext = applicationContext;
    }

    public void customInit() {
        System.out.println("8、自定义init");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("7、InitializingBean的afterPropertiesSEt");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("DisposableBean的destroy");
    }
    public void customDestroy() {
        System.out.println("自定义Destroy");
    }
}
